#include "user_functions.h"

struct sqr_: public user_function_i
{
   big_int operator()(big_int bigint)
   {
      return bigint * bigint;
   }
};

struct digits_: public user_function_i
{
   big_int operator()(big_int bigint)
   {
      big_int result = big_int(0);
      
      while (bigint > big_int(0))
      {
         result += big_int(1);
         bigint /= big_int(10);
      }
      
      return result;
   }
};

struct fact_: public user_function_i
{
   big_int operator()(big_int bigint)
   {
      big_int result = big_int(1);
      
      while (bigint > big_int(1))
      {
         result *= bigint;
         bigint -= big_int(1);
      }
      
      return result;
   }
};

struct user_functions
{
   user_functions()
   {
      function_map["sqr"] = new sqr_;
      function_map["digits"] = new digits_;
      function_map["fact"] = new fact_;
   }
   
   std::map<std::string, user_function_i*> function_map;
};

user_functions functions;

std::map<std::string, user_function_i*>& get_function()
{
   return functions.function_map;
}